package com.imooc.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.imooc.domain.MiaoshaGoods;
import com.imooc.vo.GoodsVo;

@Mapper
public interface GoodsDao {
	
	@Select("select g.*,mg.miaosha_price,mg.stock_count,mg.start_date,mg.end_date from miaosha_goods mg LEFT JOIN goods g on mg.goods_id=g.id")
	public List<GoodsVo> listGoodsVo();
	
	@Select("select g.*,mg.miaosha_price,mg.stock_count,mg.start_date,mg.end_date from miaosha_goods mg LEFT JOIN goods g on mg.goods_id=g.id where g.id=#{goodsId}")
	public GoodsVo getGoodsByGoodsId(@Param("goodsId")Long goodsId);

	@Update("update miaosha_goods set stock_count = stock_count - 1 where goods_id = #{id}")
	public Integer reduceStock(MiaoshaGoods g);
	
	@Select("select g.*,mg.stock_count, mg.start_date, mg.end_date,mg.miaosha_price from miaosha_goods mg left join goods g on mg.goods_id = g.id where g.id = #{goodsId}")
	public GoodsVo getGoodsVoByGoodsId(@Param("goodsId")long goodsId);
}
